<template>
	<view class="content padding" v-if="viewShow">
		<!-- 地址 -->
		<view class="ffffff border_2" style="padding: 60rpx;" v-if="!dataAll.address_info" @click="checkAddress">
			<view class="flexcenter">
				<view class="text_w" style="color: #F3271C;">
					点击添加收货地址
				</view>
			</view>
		</view>
		<view class="padding ffffff border_2" v-if="dataAll.address_info"  @click="checkAddress">
			<view class="flexbetween">
				<view>
					<view class="flexleft">
						<view class="color_ling text_w margin_right5">{{dataAll.address_info.name}}</view>
						<view class="color_ling text_w">{{dataAll.address_info.mobile}}</view>
					</view>
					<view class="margin_top2 color_six text_five">{{dataAll.address_info.region+dataAll.address_info.address}}</view>
				</view>
				<u-icon name="arrow-right" color="rgba(175, 175, 175, 1)" size="12"></u-icon>
			</view>
		</view>
		<view v-for="item in dataAll.shop_goods_data">
			<!-- 商品信息 -->
			<view class="margin_top padding border_2 ffffff">
				<view class="flexbetween">
					<view class="flexleft">
						<image class="imgShop margin_right1" src="/static/image/mine/dianpuRed.png" mode="widthFix"></image>
						<view class="color_ling text_z margin_right1">{{item.shop_name}}</view>
					</view>
				</view>
				<view class="flexbetween xiahuax margin_top" v-for="ite in item.goods_data">
					<view class="shilitu">
						<image :src="ite.image_text" mode="widthFix"></image>
					</view>
					<view class="" style="width: 74%;">
						<view class="yihang text_a color_san">{{ite.goods_name}}</view>
						<view class="color_jiu text_b margin_top2">{{ite.sku}}</view>
						<view class="flexbetween margin_top2">
							<view class="qianshu">¥{{ite.price}}</view>
							<view class="shuliang">X{{ite.cart_num}}</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 备注 -->
			<view class="margin_top padding border_2 ffffff">
				<view class="color_san text_w">备注</view>
				<view class="margin_top">
					<input class="text_g" type="text" placeholder="请输入留言信息给卖家"
						placeholder-style="color: #999999;font-size: 30rpx;" v-model="item.content">
				</view>
			</view>
			<!-- 支付提示 -->
			<view class="margin_top5" style="padding-bottom: 100rpx;">
				<u-parse :content="shopInfo.buy_rule"></u-parse>
			</view>
		</view>
		<!-- 底部 -->
		<view class="footerBox padding ffffff flexbetween">
			<view>
				<text class="color_san text_g">合计：</text>
				<text class="price">¥{{dataAll.total_price}}</text>
			</view>
			<view class="payment" @click="generateOrder">立即支付</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				address_id:"",
				from_type: "", //来源：detail=从商品详情跳转过去的，cart=从购物车跳转过去的
				cart_ids: "",
				goods_num: "", //	商品数量
				goods_id: "", //	商品id
				goods_sku_unique: "", //规格unique
				is_alone: "",//是否单独购买，1=是，0=否
				goods_group_buying_id:"",//拼单id
				dataAll:{},
				shopInfo:{},//支付提示
				viewShow:false
			}
		},
		async onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			this.from_type=data.from_type //来源：detail=从商品详情跳转过去的，cart=从购物车跳转过去的
			this.cart_ids=data.cart_ids
			this.goods_num=data.goods_num //	商品数量
			this.goods_id=data.goods_id //	商品id
			this.goods_sku_unique=data.goods_sku_unique //规格unique
			this.goods_group_buying_id = data.goods_group_buying_id
			this.is_alone=data.is_alone
			let res=await this.initApp()
			this.shopInfo=res.data
		},
		onShow() {
			uni.$off("selectAddressFn")
			uni.$on("selectAddressFn",data=>{
				this.address_id = data
			})
			this.getInfo()
		},
		methods:{
			getInfo(){
				let _this = this
				httpRequest.request('/api/goods_order/order_show', 'POST', {
					address_id: _this.address_id, 
					cart_ids:_this.cart_ids,
					from_type: _this.from_type, 
					goods_num: _this.goods_num, 
					goods_id: _this.goods_id, 
					goods_sku_unique: _this.goods_sku_unique, 
					is_alone: _this.is_alone,
					goods_group_buying_id:_this.goods_group_buying_id
				}, false, false, true).then(res => {
					
					console.log(11111111);
					console.log(res);
					if(res['code']==1){
						res.data.shop_goods_data.forEach(item=>{
							this.$set(item,"content","")
						})
						this.dataAll = res.data;
						this.viewShow=true;
					}else{
						httpRequest.toast(res.msg);
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						}, 2000); 
					}
					
				}).catch(err => {
					
					httpRequest.toast(err.msg);
					
				})
			},
			// 生成订单
			generateOrder(){
				let _this = this
				if(!_this.dataAll.address_info||!_this.dataAll.address_info.id){
					httpRequest.toast("请选择地址")
					return false
				}
				let arr = []
				this.dataAll.shop_goods_data.forEach(item=>{
					arr.push({
						shop_id:item.shop_id,
						content:item.content
					})
				})
				let data = {
					address_id: _this.dataAll.address_info.id,
					cart_ids:_this.cart_ids,
					from_type: _this.from_type, 
					goods_num: _this.goods_num, 
					goods_id: _this.goods_id, 
					goods_sku_unique: _this.goods_sku_unique, 
					is_alone: _this.is_alone,
					goods_group_buying_id:_this.goods_group_buying_id,
					remarks:arr,
					total_price:this.dataAll.total_price
				}
				uni.redirectTo({
					url:"/pages_index/payment?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			checkAddress(){
				uni.navigateTo({
					url:"/pages_mine/takeAddress?type=1"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding-bottom: 110rpx;
	}

	.imgShop {
		width: 26.62rpx;
		height: 24rpx;
	}

	.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;
 overflow: hidden;
		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.qianshu {
		font-size: 30rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: rgba(243, 39, 28, 1);
	}

	.footerBox {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		box-sizing: border-box;
	}

	.price {
		font-size: 36rpx;
		font-family: DIN-Bold, DIN;
		font-weight: bold;
		color: #F3271C;
	}

	.payment {
		width: 250rpx;
		height: 76rpx;
		line-height: 76rpx;
		text-align: center;
		background: #F3271C;
		border-radius: 120rpx 120rpx 120rpx 120rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
</style>